import axios from "axios"

let http = new Object;
http.response = '';
http.err = '';
/*
*@ get请求
*@ url (string) 请求的地址
*/
http.get = function(url,parameter,config){
    console.log(url)
    var getResult = axios.get(url,parameter,config)
    getResult.then(function(response){
        http.response = response;
    })
    getResult.catch(function(err){
        http.err = err;
    })
    return getResult;
}
/*
*@ post请求
*@ url (string) 请求的地址
*@ parameter (json) 参数 
*/
http.post = function(url,parameter,config){
    var getResult = axios.post(url, parameter,config);
    getResult.then(function(response){
        http.response = response;
    })
    getResult.catch(function(err){
        http.err = err;
    })
    return getResult;
}
/*
*@ 请求成功执行的函数
*/
http.then = function(func){
    func(http.response)
}
/*
*@ 请求失败执行的函数
*/
http.catch = function(func){
    func(http.err);
}

export default http;
